Type.registerNamespace("Telerik.Web.UI.Scheduler.Views.Month.GroupedByResource");
(function(b){var a=b.Views.Month;
a.GroupedByResource.Model=function(c,e,d){a.GroupedByResource.Model.initializeBase(this,[c]);
this._groupingResource=e;
this._isVertical=d;
this._monthModels=[];
this._resources=null;
};
a.GroupedByResource.Model.prototype={initialize:function(){this._resources=this._owner.get_resources().getResourcesByType(this._groupingResource);
for(var c=0;
c<this._resources.get_count();
c++){this._monthModels[c]=new a.Model(this._owner);
}},addToBlocks:function(d){var c=this._getAppointmentModelIndex(d.appointment);
d.appointment.__modelIndex=c;
this._monthModels[c].addToBlocks(d);
},removeFromBlock:function(d){var c=d.appointment.__modelIndex;
this._monthModels[c].removeFromBlock(d);
},getTimeSlotFromDomElement:function(e){var d=this._getRawIndexFromDomElement(e);
if(!d){return null;
}var c=this._getTimeFromDomElement(e);
var f=this._resources.getResource(d.modelIndex);
return new a.GroupedByResource.TimeSlot(d,c,f,e);
},_getAllDayTimeSlotForAppointmentPart:function(c){return this._getAllDayTimeSlot(c.start,c.modelIndex);
},_getAllDayTimeSlot:function(e,g){var c=this._getTimeSlotIndices(e);
c.modelIndex=g;
var f=this._resources.getResource(g);
var d=this._getTimeSlotDomElement(c);
return new a.GroupedByResource.TimeSlot(c,e,f,d);
},getTimeSlotForAppointment:function(c){var d=this._getAppointmentModelIndex(c);
if(d==-1){return null;
}return this._getAllDayTimeSlot(c.get_start(),d);
},_getAppointmentModelIndex:function(c){var d=-1;
var e=this;
c.get_resources().forEach(function(f){var g=e._resources.getResourceByTypeAndKey(f.get_type(),f.get_key());
if(g){d=Array.indexOf(e._resources._array,g);
}});
return d;
},_getTimeSlotDomElement:function(c){var g=c.modelIndex||0;
var f=this._owner.get_element();
var h=Math.floor(c.dayIndex/this.get_weekLength());
var e=Math.floor(c.dayIndex%this.get_weekLength());
var d=this._owner._modelTables[g];
return d.tBodies[0].rows[h].cells[e];
},_getTimeFromDomElement:function(c){return this._monthModels[0]._getTimeFromDomElement(c);
},_getRawIndexFromDomElement:function(c){while(c&&(c.tagName.toUpperCase()!="TD")){c=c.parentNode;
}if(!c){return null;
}var j=c.parentNode;
var h=j.parentNode;
var e=h.parentNode;
var d=this._owner._modelTables;
var i=this._owner._getElementIndex(d,e);
var g=this._monthModels[i];
var f=null;
if(g){f=g._getRawIndexFromDomElement(c);
f.modelIndex=i;
}return f;
},isVisible:function(c){var d=a.GroupedByResource.Model.callBaseMethod(this,"isVisible",[c]);
var e=this._getAppointmentModelIndex(c)!=-1;
return d&&e;
},_getRenderer:function(){if(!this._renderer){this._renderer=new b.Rendering.ResourceGroupedMonthViewRenderer(this);
}return this._renderer;
}};
a.GroupedByResource.Model.registerClass("Telerik.Web.UI.Scheduler.Views.Month.GroupedByResource.Model",a.ModelBase);
a.GroupedByResource.TimeSlot=function(d,c,f,e){this._resource=f;
a.GroupedByResource.TimeSlot.initializeBase(this,[d,c,e]);
};
a.GroupedByResource.TimeSlot.prototype={get_index:function(){var c=this.get_rawIndex();
var d=a.GroupedByResource.TimeSlot.callBaseMethod(this,"get_index");
return String.format("{0}:{1}",c.modelIndex,d);
},get_resource:function(){return this._resource;
}};
a.GroupedByResource.TimeSlot.registerClass("Telerik.Web.UI.Scheduler.Views.Month.GroupedByResource.TimeSlot",a.TimeSlot);
})(Telerik.Web.UI.Scheduler);
